package com.coolingme.auth.v2chain.handler;

import com.coolingme.auth.Member;
import com.coolingme.auth.v2chain.AbstractAuthHandler;

/**
 * 认证
 *
 * @author wangyue
 * @date 2020-09-23 21:29
 */
public class LoginHandler extends AbstractAuthHandler {
    @Override
    public void doAuth(Member member) {
        // 从数据库获取数据，还应该验证密码是否相同
        member = checkExists(member.getLoginName());
        if (null == member) {
            System.out.println("用户不存在");
            return;
        }
        System.out.println("登录成功！");
        // 执行下一个处理器
        chain.doAuth(member);
    }

    /**
     * 假装从数据库获取
     *
     * @param loginName loginName
     * @return Member
     */
    private Member checkExists(String loginName) {
        Member member = null;
        if ("admin".equals(loginName)) {
            member = new Member(loginName, null, "管理员");
        } else {
            member = new Member(loginName, null, "普通用户");
        }
        return member;
    }
}
